home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / cloak.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  290 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. static struct osd_bitmap *tmpbitmap2,*charbitmap;
  14. static unsigned char x,y,bmap;
  15. static unsigned char *tmpvideoram,*tmpvideoram2;
  16.  
  17.  
  18. void cloak_vh_stop(void);
  19.  
  20.  
  21. /***************************************************************************
  22.  
  23.   CLOAK & DAGGER uses RAM to dynamically
  24.   create the palette. The resolution is 9 bit (3 bits per gun). The palette
  25.   contains 64 entries, but it is accessed through a memory windows 128 bytes
  26.   long: writing to the first 64 bytes sets the msb of the red component to 0,
  27.   while writing to the last 64 bytes sets it to 1.
  28.  
  29.   Colors 0-15  Character mapped graphics
  30.   Colors 16-31 Bitmapped graphics (maybe 8 colors per bitmap?)
  31.   Colors 32-47 Sprites
  32.   Colors 48-63 not used
  33.  
  34.   I don't know the exact values of the resistors between the RAM and the
  35.   RGB output, I assumed the usual ones.
  36.   bit 8 -- inverter -- 220 ohm resistor  -- RED
  37.         -- inverter -- 470 ohm resistor  -- RED
  38.         -- inverter -- 1  kohm resistor  -- RED
  39.         -- inverter -- 220 ohm resistor  -- GREEN
  40.         -- inverter -- 470 ohm resistor  -- GREEN
  41.         -- inverter -- 1  kohm resistor  -- GREEN
  42.         -- inverter -- 220 ohm resistor  -- BLUE
  43.         -- inverter -- 470 ohm resistor  -- BLUE
  44.   bit 0 -- inverter -- 1  kohm resistor  -- BLUE
  45.  
  46. ***************************************************************************/
  47. WRITE_HANDLER( cloak_paletteram_w )
  48. {
  49.     int r,g,b;
  50.     int bit0,bit1,bit2;
  51.  
  52.  
  53.     /* a write to offset 64-127 means to set the msb of the red component */
  54.     data |= (offset & 0x40) << 2;
  55.  
  56.     r = (~data & 0x1c0) >> 6;
  57.     g = (~data & 0x038) >> 3;
  58.     b = (~data & 0x007);
  59.  
  60.     bit0 = (r >> 0) & 0x01;
  61.     bit1 = (r >> 1) & 0x01;
  62.     bit2 = (r >> 2) & 0x01;
  63.     r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  64.     bit0 = (g >> 0) & 0x01;
  65.     bit1 = (g >> 1) & 0x01;
  66.     bit2 = (g >> 2) & 0x01;
  67.     g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  68.     bit0 = (b >> 0) & 0x01;
  69.     bit1 = (b >> 1) & 0x01;
  70.     bit2 = (b >> 2) & 0x01;
  71.     b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  72.  
  73.     palette_change_color(offset & 0x3f,r,g,b);
  74. }
  75.  
  76.  
  77. WRITE_HANDLER( cloak_clearbmp_w )
  78. {
  79.     bmap = data & 1;
  80.     if (data & 2)    /* clear */
  81.     {
  82.         if (bmap)
  83.         {
  84.             fillbitmap(tmpbitmap, Machine->pens[16], &Machine->drv->visible_area);
  85.             memset(tmpvideoram, 0, 256*256);
  86.         }
  87.         else
  88.         {
  89.             fillbitmap(tmpbitmap2, Machine->pens[16], &Machine->drv->visible_area);
  90.             memset(tmpvideoram2, 0, 256*256);
  91.         }
  92.     }
  93. }
  94.  
  95.  
  96. static void adjust_xy(int offset)
  97. {
  98.     switch(offset)
  99.     {
  100.     case 0x00:  x--; y++; break;
  101.     case 0x01:       y--; break;
  102.     case 0x02:  x--;      break;
  103.     case 0x04:  x++; y++; break;
  104.     case 0x05:       y++; break;
  105.     case 0x06:  x++;      break;
  106.     }
  107. }
  108.  
  109.  
  110. READ_HANDLER( graph_processor_r )
  111. {
  112.     int ret;
  113.  
  114.     if (bmap)
  115.     {
  116.         ret = tmpvideoram2[y*256+x];
  117.     }
  118.     else
  119.     {
  120.         ret = tmpvideoram[y*256+x];
  121.     }
  122.  
  123.     adjust_xy(offset);
  124.  
  125.     return ret;
  126. }
  127.  
  128.  
  129. WRITE_HANDLER( graph_processor_w )
  130. {
  131.     int col;
  132.  
  133.     switch (offset)
  134.     {
  135.     case 0x03:  x=data; break;
  136.     case 0x07:  y=data; break;
  137.     default:
  138.         col = data & 0x07;
  139.  
  140.         if (bmap)
  141.         {
  142.             plot_pixel(tmpbitmap, (x-6)&0xff, y, Machine->pens[16 + col]);
  143.             tmpvideoram[y*256+x] = col;
  144.         }
  145.         else
  146.         {
  147.             plot_pixel(tmpbitmap2, (x-6)&0xff, y, Machine->pens[16 + col]);
  148.             tmpvideoram2[y*256+x] = col;
  149.         }
  150.  
  151.         adjust_xy(offset);
  152.         break;
  153.     }
  154. }
  155.  
  156.  
  157. /***************************************************************************
  158.  
  159.   Start the video hardware emulation.
  160.  
  161. ***************************************************************************/
  162. int cloak_vh_start(void)
  163. {
  164.     if ((tmpbitmap = osd_create_bitmap(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  165.         return 1;
  166.  
  167.     if ((charbitmap = osd_create_bitmap(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  168.     {
  169.         cloak_vh_stop();
  170.         return 1;
  171.     }
  172.  
  173.     if ((tmpbitmap2 = osd_create_bitmap(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  174.     {
  175.         cloak_vh_stop();
  176.         return 1;
  177.     }
  178.  
  179.     if ((dirtybuffer = malloc(videoram_size)) == 0)
  180.     {
  181.         cloak_vh_stop();
  182.         return 1;
  183.     }
  184.     memset(dirtybuffer,1,videoram_size);
  185.  
  186.     if ((tmpvideoram = malloc(256*256)) == 0)
  187.     {
  188.         cloak_vh_stop();
  189.         return 1;
  190.     }
  191.  
  192.     if ((tmpvideoram2 = malloc(256*256)) == 0)
  193.     {
  194.         cloak_vh_stop();
  195.         return 1;
  196.     }
  197.  
  198.     return 0;
  199. }
  200.  
  201. /***************************************************************************
  202.  
  203.   Stop the video hardware emulation.
  204.  
  205. ***************************************************************************/
  206. void cloak_vh_stop(void)
  207. {
  208.     if (charbitmap)  osd_free_bitmap(charbitmap);
  209.     if (tmpbitmap2)  osd_free_bitmap(tmpbitmap2);
  210.     if (tmpbitmap)   osd_free_bitmap(tmpbitmap);
  211.     if (dirtybuffer) free(dirtybuffer);
  212.     if (tmpvideoram) free(tmpvideoram);
  213.     if (tmpvideoram2) free(tmpvideoram2);
  214. }
  215.  
  216.  
  217. /***************************************************************************
  218.  
  219.   Draw the game screen in the given osd_bitmap.
  220.   Do NOT call osd_update_display() from this function, it will be called by
  221.   the main emulation engine.
  222.  
  223. ***************************************************************************/
  224. static void refresh_bitmaps(void)
  225. {
  226.     int lx,ly;
  227.  
  228.     for (ly = 0; ly < 256; ly++)
  229.     {
  230.         for (lx = 0; lx < 256; lx++)
  231.         {
  232.             plot_pixel(tmpbitmap,  (lx-6)&0xff, ly, Machine->pens[16 + tmpvideoram[ly*256+lx]]);
  233.             plot_pixel(tmpbitmap2, (lx-6)&0xff, ly, Machine->pens[16 + tmpvideoram2[ly*256+lx]]);
  234.         }
  235.     }
  236. }
  237.  
  238.  
  239. void cloak_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  240. {
  241.     int offs;
  242.  
  243.  
  244.     palette_used_colors[16] = PALETTE_COLOR_TRANSPARENT;
  245.     if (palette_recalc())
  246.     {
  247.         memset(dirtybuffer, 1, videoram_size);
  248.  
  249.         refresh_bitmaps();
  250.     }
  251.  
  252.     /* for every character in the Video RAM, check if it has been modified */
  253.     /* since last time and update it accordingly. */
  254.     for (offs = videoram_size - 1;offs >= 0;offs--)
  255.     {
  256.         if (dirtybuffer[offs])
  257.         {
  258.             int sx,sy;
  259.  
  260.  
  261.             dirtybuffer[offs] = 0;
  262.  
  263.             sx = offs % 32;
  264.             sy = offs / 32;
  265.  
  266.             drawgfx(charbitmap,Machine->gfx[0],
  267.                     videoram[offs],0,
  268.                     0,0,
  269.                     8*sx,8*sy,
  270.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  271.         }
  272.     }
  273.  
  274.     /* copy the temporary bitmap to the screen */
  275.     copybitmap(bitmap,charbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  276.     copybitmap(bitmap, bmap ? tmpbitmap2 : tmpbitmap, 0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
  277.  
  278.  
  279.     /* Draw the sprites */
  280.     for (offs = spriteram_size/4-1; offs >= 0; offs--)
  281.     {
  282.         drawgfx(bitmap,Machine->gfx[1],
  283.                 spriteram[offs+64] & 0x7f,
  284.                 0,
  285.                 spriteram[offs+64] & 0x80,0,
  286.                 spriteram[offs+192],240-spriteram[offs],
  287.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  288.     }
  289. }
  290.